package org.bootstrap.tool;

import cn.hutool.core.util.BooleanUtil;

import java.util.function.Consumer;

@SuppressWarnings("all")
/**
 *@example BooleanOptional.of(Boolean.FALSE).isTrue(s - > {
 *Console.log ( " 当前值为 { } ", s);
 *         }).isFalse(f -> {
 *             Console.error("当前值为{}", f);
 *         });
 */
public class BooleanOptional {

    private static BooleanOptional booleanOptional = null;
    private static boolean val;

    static {
        booleanOptional = new BooleanOptional();
    }

    public static BooleanOptional of(Boolean b) {
        val = b;
        return booleanOptional;
    }

    public <T> BooleanOptional isTrue(Consumer<Boolean> c) {
        if (BooleanUtil.isTrue(val)) {
            c.accept(val);
        }
        return booleanOptional;
    }

    public <T> BooleanOptional isFalse(Consumer<Boolean> c) {
        if (BooleanUtil.isFalse(val)) {
            c.accept(val);
        }
        return booleanOptional;
    }
}
